import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:ui/api/config.dart';

class UpdatePricesLogic extends GetxController {
  final TextEditingController pricesCtrl = TextEditingController();
  TextStyle pricesTextStyle() => const TextStyle(fontSize: 32);
  TextStyle pricesTimeStyle() => const TextStyle(fontSize: 22);

  RxDouble nowPrices = 0.0.obs;
  RxString pricesUpdateTime = "2024-01-02 03:04:05".obs;
  getmsg(String topic) {
    config.apihttp.getmsg(config.settingLogic.uid.value, topic).then((onValue) {
      print("获取数据->$onValue");
      String msgTime = onValue['time'];
      double prices = double.parse(onValue['msg']);
      nowPrices.value = prices;
      pricesUpdateTime.value = msgTime;
    });
  }

  pushmsg(String topic, String data) {
    config.apihttp
        .pushmsg(config.settingLogic.uid.value, topic, data)
        .then((onValue) {
      // debugPrint("onValue$onValue");
      // 重新获取更新后的数据
      getmsg(topic);
    });
  }

  // @override
  // void onInit() {
  //   super.onInit();
  //   nowPrices.value == 0.0;
  // }
  @override
  void onClose() {
    super.onClose();
    debugPrint("UpdatePrices->onClose");
    nowPrices.value == 0.0;
  }
}
